
//这个变量是像首页这个页面如果同时调取好几个接口
let ajaxTime = 0
export const request = (params) => {
  ajaxTime++
  wx.showLoading({
    title: "加载中",
    mask: true,
  });

  const baseURL = "https://api-hmugo-web.itheima.net/api/public/v1"
  return new Promise((resolve, reject) => {
    wx.request({
      url: baseURL + params.url,
      data: params.data,
      method: params.method ? params.method : "get",
      Headers: params.header ? params.header : '',
      success: (result) => {
        resolve(result)
      },
      fail: (err) => {
        reject(err)
      },
      complete: () => {
        ajaxTime--
        //那么是需要几个接口数据都返回再去关闭
        if (ajaxTime == 0) {
          wx.hideLoading();
        }
      }
    })
  })
}